package com.ruoyi.easyfame.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.easyfame.domain.Demands;
import com.ruoyi.easyfame.service.IDemandsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 买家需求Controller
 * 
 * @author xhb
 * @date 2025-08-27
 */
@RestController
@RequestMapping("/easyfame/demands")
public class DemandsController extends BaseController
{
    @Autowired
    private IDemandsService demandsService;

    /**
     * 查询买家需求列表
     */
    @PreAuthorize("@ss.hasPermi('easyfame:demands:list')")
    @GetMapping("/list")
    public TableDataInfo list(Demands demands)
    {
        startPage();
        List<Demands> list = demandsService.selectDemandsList(demands);
        return getDataTable(list);
    }

    /**
     * 导出买家需求列表
     */
    @PreAuthorize("@ss.hasPermi('easyfame:demands:export')")
    @Log(title = "买家需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Demands demands)
    {
        List<Demands> list = demandsService.selectDemandsList(demands);
        ExcelUtil<Demands> util = new ExcelUtil<Demands>(Demands.class);
        util.exportExcel(response, list, "买家需求数据");
    }

    /**
     * 获取买家需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('easyfame:demands:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(demandsService.selectDemandsById(id));
    }

    /**
     * 新增买家需求
     */
    @PreAuthorize("@ss.hasPermi('easyfame:demands:add')")
    @Log(title = "买家需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Demands demands)
    {
        return toAjax(demandsService.insertDemands(demands));
    }

    /**
     * 修改买家需求
     */
    @PreAuthorize("@ss.hasPermi('easyfame:demands:edit')")
    @Log(title = "买家需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Demands demands)
    {
        return toAjax(demandsService.updateDemands(demands));
    }

    /**
     * 删除买家需求
     */
    @PreAuthorize("@ss.hasPermi('easyfame:demands:remove')")
    @Log(title = "买家需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(demandsService.deleteDemandsByIds(ids));
    }
}
